Release image buffer (this API is used to release the image buffer, which is no longer used, and it should be used with API: MV_CC_GetImageBuffer).
int MV_CC_FreeImageBuffer( void *handle, MV_FRAME_OUT *pFrame, );
[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.
[IN] Image data and information
Return MV_OK(0) on success, and return Error Code on failure.
This API and MV_CC_GetImageBuffer should be called in pairs, before calling MV_CC_GetImageBuffer to get image data pFrame, you should call MV_CC_FreeImageBuffer to release the permission.
Compared with API MV_CC_GetOneFrameTimeout, this API has higher efficiency of image acquisition. The max. number of nodes can be outputted is same as the "nNum" of API MV_CC_SetImageNodeNum, default value is 1.
This API is not supported by CameraLink device.
This API is supported by both USB3 vision camera and GigE camera.
The following sample code is for reference only.
#include "MvCameraControl.h"
void main()
{
int nRet = -1;
void* m_handle = NULL;
//Enumerate all devices corresponding to specified transport protocol within subnet
unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
if (MV_OK != nRet)
{
printf("error: EnumDevices fail [%x]\n", nRet);
return;
}
int i = 0;
if (m_stDevList.nDeviceNum == 0)
{
printf("no camera found!\n");
return;
}
//Select the first found online device and create device handle
int nDeviceIndex = 0;
MV_CC_DEVICE_INFO m_stDevInfo = {0};
memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));
nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);
if (MV_OK != nRet)
{
printf("error: CreateHandle fail [%x]\n", nRet);
return;
}
//Connect to device
nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
if (MV_OK != nRet)
{
printf("error: OpenDevice fail [%x]\n", nRet);
return;
}
//...other processing
//Start acquiring images
nRet = MV_CC_StartGrabbing(m_handle);
if (MV_OK != nRet)
{
printf("error: StartGrabbing fail [%x]\n", nRet);
return;
}
MV_FRAME_OUT stOutFrame;
memset(&stOutFrame, 0, sizeof(MV_FRAME_OUT));
//The upper layer should control the frequency of calling this API according to frame rate.
//The codes are for reference only, it is recommended to create a new thread for image acquisition and processing
while(1)
{
if (nTestFrameSize > 99)
{
break;
}
nRet = MV_CC_GetImageBuffer(m_handle, &stOutFrame, 1000);
if (MV_OK != nRet)
{
Sleep(10);
}
else
{
//...Process image data
nTestFrameSize++;
}
nRet = MV_CC_FreeImageBuffer(m_handle, &stOutFrame);
if(nRet != MV_OK) { printf("Free Image Buffer fail! nRet [0x%x]\n", nRet);
}
}
//...other processing
//Stop image acquisition
nRet = MV_CC_StopGrabbing(m_handle);
if (MV_OK != nRet)
{
printf("error: StopGrabbing fail [%x]\n", nRet);
return;
}
//Close device, and release resource
nRet = MV_CC_CloseDevice(m_handle);
if (MV_OK != nRet)
{
printf("error: CloseDevice fail [%x]\n", nRet);
return;
}
//Destroy handle and release resource
nRet = MV_CC_DestroyHandle(m_handle);
if (MV_OK != nRet)
{
printf("error: DestroyHandle fail [%x]\n", nRet);
return;
}
}
Release image buffer (this API is used to release the image buffer, which is no longer used, and it should be used with API: MV_CC_GetImageBuffer).
int MV_CC_FreeImageBuffer( void *handle, MV_FRAME_OUT *pFrame, );
[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.
[IN] Image data and information
Return MV_OK(0) on success, and return Error Code on failure.
This API and MV_CC_GetImageBuffer should be called in pairs, before calling MV_CC_GetImageBuffer to get image data pFrame, you should call MV_CC_FreeImageBuffer to release the permission.
Compared with API MV_CC_GetOneFrameTimeout, this API has higher efficiency of image acquisition. The max. number of nodes can be outputted is same as the "nNum" of API MV_CC_SetImageNodeNum, default value is 1.
This API is not supported by CameraLink device.
This API is supported by both USB3 vision camera and GigE camera.
The following sample code is for reference only.
#include "MvCameraControl.h"
void main()
{
int nRet = -1;
void* m_handle = NULL;
//Enumerate all devices corresponding to specified transport protocol within subnet
unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
if (MV_OK != nRet)
{
printf("error: EnumDevices fail [%x]\n", nRet);
return;
}
int i = 0;
if (m_stDevList.nDeviceNum == 0)
{
printf("no camera found!\n");
return;
}
//Select the first found online device and create device handle
int nDeviceIndex = 0;
MV_CC_DEVICE_INFO m_stDevInfo = {0};
memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));
nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);
if (MV_OK != nRet)
{
printf("error: CreateHandle fail [%x]\n", nRet);
return;
}
//Connect to device
nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
if (MV_OK != nRet)
{
printf("error: OpenDevice fail [%x]\n", nRet);
return;
}
//...other processing
//Start acquiring images
nRet = MV_CC_StartGrabbing(m_handle);
if (MV_OK != nRet)
{
printf("error: StartGrabbing fail [%x]\n", nRet);
return;
}
MV_FRAME_OUT stOutFrame;
memset(&stOutFrame, 0, sizeof(MV_FRAME_OUT));
//The upper layer should control the frequency of calling this API according to frame rate.
//The codes are for reference only, it is recommended to create a new thread for image acquisition and processing
while(1)
{
if (nTestFrameSize > 99)
{
break;
}
nRet = MV_CC_GetImageBuffer(m_handle, &stOutFrame, 1000);
if (MV_OK != nRet)
{
Sleep(10);
}
else
{
//...Process image data
nTestFrameSize++;
}
nRet = MV_CC_FreeImageBuffer(m_handle, &stOutFrame);
if(nRet != MV_OK) { printf("Free Image Buffer fail! nRet [0x%x]\n", nRet);
}
}
//...other processing
//Stop image acquisition
nRet = MV_CC_StopGrabbing(m_handle);
if (MV_OK != nRet)
{
printf("error: StopGrabbing fail [%x]\n", nRet);
return;
}
//Close device, and release resource
nRet = MV_CC_CloseDevice(m_handle);
if (MV_OK != nRet)
{
printf("error: CloseDevice fail [%x]\n", nRet);
return;
}
//Destroy handle and release resource
nRet = MV_CC_DestroyHandle(m_handle);
if (MV_OK != nRet)
{
printf("error: DestroyHandle fail [%x]\n", nRet);
return;
}
}